﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BlueMarineWindowsFormsClient.InternalServiceReference;

namespace BlueMarineWindowsFormsClient
{
    public partial class frmSearchRoom : Form
    {
        private InternalServiceClient _Search;
        public frmSearchRoom()
        {
            InitializeComponent();
            _Search = new InternalServiceClient("nettcp");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            int minPrice = Convert.ToInt32(cbMinPrice.SelectedItem.ToString());
            int maxPrice = Convert.ToInt32(cbMaxPrice.SelectedItem.ToString());
            List<RoomType> listRoomType = _Search.SearchByPrice(minPrice, maxPrice);
            if (listRoomType.Count > 0)
                grdRoomType.DataSource = listRoomType;
            else
                lblStatus.Text = "Not found";

            
        }

        private void cbMinPrice_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbMaxPrice.Items.Clear();

            int i = Convert.ToInt32(cbMinPrice.SelectedItem.ToString());
            while (i < 100)
            {                
                cbMaxPrice.Items.Add(i += 10);
            }
        }

        private void grdRoomType_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int roomTypeId = Convert.ToInt32(grdRoomType.Rows[e.RowIndex].Cells[0].Value.ToString());
            DateTime inDate = dtpFrom.Value;
            DateTime outDate = dtpTo.Value;


            List<int> listRoomId = _Search.getAvailableRoomID(roomTypeId, inDate, outDate);
            MessageBox.Show(listRoomId[0].ToString());
            if (listRoomId.Count > 0)
                grdRoomId.DataSource = listRoomId;
            else
                lblStatus.Text = "Not found";
        }
    }
}
